package com.urlshortener

class BtlyURL {


	
	static String shorten(String login,String apikey,String format,String longUrl){
		
	
		def addr	="http://api.bitly.com/v3/shorten?login=${login}&apiKey=${apikey}&longUrl=${longUrl}&format=${format}"
    def url = addr.toURL()
    def urlConnection = url.openConnection()
    if(urlConnection.responseCode == 200){
      return urlConnection.content.text
    }else{
      return "An error occurred: ${addr}\n" + 
      "${urlConnection.responseCode} : ${urlConnection.responseMessage}"
    }
	  }
}
